package com.spring;

import com.spring.pojo.User;
import com.spring.service.UserService;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class SpringDemo2 {
    public static void main(String[] args) {
        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("application-context2.xml");
        Object obj = ctx.getBean("person4");
        System.out.println(obj);
        // 关闭spring容器
        ctx.close();
    }

    private static void demo3() {
        ApplicationContext ctx = new ClassPathXmlApplicationContext("application-context2.xml");
        Object obj = ctx.getBean("person3");
        Object obj2 = ctx.getBean("person3");
        Object obj3 = ctx.getBean("person3");
        System.out.println(obj);
        System.out.println(obj2);
        System.out.println(obj3);
    }

    private static void demo2() {
        ApplicationContext ctx = new ClassPathXmlApplicationContext("application-context2.xml");
        Object obj = ctx.getBean("person2");
        System.out.println(obj);

        List<String> list = new ArrayList<>();
        Collection<String> coll = new ArrayList<>();
    }

    private static void demo1() {
        // 获取到Spring的核心对象
        ApplicationContext ctx = new ClassPathXmlApplicationContext("application-context2.xml");
        Object obj = ctx.getBean("person");
        System.out.println(obj);
    }
}
